// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import store from './store/index.js'
import iview from 'view-design'
import * as iViewPro from '@/libs/iview-pro/iview-pro.min.js'
import 'moment/locale/zh-cn'
import 'view-design/dist/styles/iview.css'
import '@/libs/iview-pro/iview-pro.css';
import exportBtn from '@/components/ExportBtn';
import router from './router'
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
Vue.use(Viewer, {
  defaultOptions: {
    zIndex: 9999,
    url: function (e) {
      return e.src.replace('_110w', '')
    }
  }
})
// 聊天
// import SocketIO from 'socket.io-client';
// import VueSocketIO from 'vue-socket.io';
// console.log(SocketIO('ws://39.101.193.254:9502'))
// Vue.use(new VueSocketIO({
//   debug: false,
//   connection: SocketIO('ws://39.101.193.254:9502') 
// }));
Vue.use(iview)
Vue.use(iViewPro)
Vue.component('export-btn', exportBtn);
iview.InputNumber.computed.precisionValue = function () {
  let arr = (this.currentValue + '').split('.')
  if (this.precision && arr[1] && this.precision < arr[1].length) { return this.currentValue.toFixed(this.precision) }
  return this.currentValue
}
// Vue.use(vcolorpicker)

// vue自定义组件，原型添加属性
import './plugins';

Vue.config.devtools = true
window.$pageSize = 20

//兼容 transfer-dom.js中 使用了 dataset 的问题
if (window.HTMLElement) {
  if (Object.getOwnPropertyNames(HTMLElement.prototype).indexOf('dataset') === -1) {
    Object.defineProperty(HTMLElement.prototype, 'dataset', {
      get: function() {
        var attributes = this.attributes //获取节点的所有属性
        var name = [],
          value = [] //定义两个数组保存属性名和属性值
        var obj = {} //定义一个空对象
        for (var i = 0; i < attributes.length; i++) { //遍历节点的所有属性
          if (attributes[i].nodeName.slice(0, 5) == 'data-') { //如果属性名的前面5个字符符合"data-"
            // 取出属性名的"data-"的后面的字符串放入name数组中
            name.push(attributes[i].nodeName.slice(5))
            //取出对应的属性值放入value数组中
            value.push(attributes[i].nodeValue)
          }
        }
        for (var j = 0; j < name.length; j++) { //遍历name和value数组
          obj[name[j]] = value[j] //将属性名和属性值保存到obj中
        }
        return obj //返回对象
      }
    })
  }
}

Vue.config.productionTip = false

/* eslint-disable no-new */
window.app = new Vue({
  el: '#app',
  router,
  store,
  render: h => h('App'),
  components: { App }
})

window.$router = window.app.$router